public class Demo4 {
    public static void main(String[] args) throws InterruptedException {
        Object locker1 = new Object();
        Object locker2 = new Object();

        Thread thread1 = new Thread(() -> {
            synchronized(locker1) {
                try {
                    locker1.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName());
            }
        });

        Thread thread2 = new Thread(() -> {
            synchronized(locker2) {
                try {
                    locker2.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName());
            }
        });

        thread1.start();
        thread2.start();

        thread1.join(1000);
        thread2.join(1000);

        synchronized(locker1) {
            locker1.notify();
        }

        synchronized(locker2) {
            locker2.notify();
        }
    }
}
